#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdio.h>

#define SOCK_PATH "/tmp/mysocket"

int main() {
	    int server_fd, client_fd;
	        struct sockaddr_un addr;
		    char buf[100];

		        // 1. 创建套接字
			     server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
			         
			             // 2. 绑定地址
			                 memset(&addr, 0, sizeof(addr));
			                     addr.sun_family = AF_UNIX;
			                         strcpy(addr.sun_path, SOCK_PATH);
			                             bind(server_fd, (struct sockaddr*)&addr, sizeof(addr));
			                                 
			                                     // 3. 监听并接受连接
			                                         listen(server_fd, 5);
			                                             client_fd = accept(server_fd, NULL, NULL);
			                                                 
			                                                     // 4. 全双工通信
			                                                         write(client_fd, "Server Message", 14);
			                                                             read(client_fd, buf, sizeof(buf));
			                                                                 printf("Server received: %s\n", buf);
			                                                                     
			                                                                         close(client_fd);
			                                                                             unlink(SOCK_PATH); // 删除套接字文件
			                                                                                 return 0;
			                                                                                 }
